import time

import requests
from faker import Faker

f = Faker(locale='zh_CN')

from Config.config import getConfig

# response_json = requests.get(getConfig("base_url", "training_url")+'/usr/list?text=12111111', headers=eval(getConfig('admin', "cookie"))).json()
# print(response_json['users'])
# for i in response_json['users']:
#     # url = getConfig("base_url", "training_url")+'/usr/deleteUser?user={}'.format(i['_id'])
#     url = "http://172.16.60.164"+'/usr/deleteUser?user={}'.format(i['_id'])
#     res = requests.delete(url, headers=eval(getConfig('admin', "cookie")))
#     while(res.status_code == 429):
#         res = requests.delete(url, headers = eval(getConfig('admin', "cookie")))
#         time.sleep(10)
#     print(url)




headers = eval(getConfig("admin", "cookie"))
for i in range(1000):
    name = f.name()
    body = {"department": "院校部门",
            "mail": name+str(i),
            "name": "jyjceshi"+name,
            "pass": "Aa111111!",
            "role": "user"}

    add_response = requests.post(getConfig("base_url", "training_url")+"/usr/createUser", headers=headers, data=body)
    print(add_response.text)
    while(add_response.status_code == 429):
        add_response = requests.post(getConfig("base_url", "training_url")+"/usr/createUser", headers=headers, data=body)

#
#     print(add_response.status_code)